using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VZUTEI
    {
        public void SetUpNewRow(ref DataRow dwReturn, DataRow dwInput = null)
        {

            switch (app.company)
            {
                default:
                case "YGR":
                    #region====YGR======
                    dwReturn["ZUMANDANT"] = "00";
                    dwReturn["ZUAUFKRS"] = "ZT";
                    dwReturn["ZUAUFLFD"] = "000004";
                    dwReturn["ZUAUFPOS"] = "001";
                    dwReturn["ZUSA"] = "713";
                    dwReturn["ZUTEILNR"] = "0000";
                    dwReturn["ZUPOS"] = "01";
                    dwReturn["ZUPARTIE"] = "0000006";
                    dwReturn["ZUPARTIEKZ"] = "0";
                    dwReturn["ZULO"] = "01";
                    dwReturn["ZULB"] = "CS";
                    dwReturn["ZULBEHI"] = "0000000020";
                    dwReturn["ZUAENDZL"] = "0";
                    dwReturn["ZUAENDBEN"] = "        ";
                    dwReturn["ZUAENDDAT"] = "0";
                    dwReturn["ZUNEUBEN"] = "INTEXE  ";
                    dwReturn["ZUNEUDAT"] = "0";
                    dwReturn["ZUEINTKG"] = "32000";
                    dwReturn["ZUEINTSP"] = "0";
                    dwReturn["ZUEINTKA"] = "0";
                    dwReturn["ZUENTNKG"] = "0";
                    dwReturn["ZUENTNSP"] = "0";
                    dwReturn["ZUENTNKA"] = "0";
                    dwReturn["ZULIEFZWP"] = "          ";
                    dwReturn["ZUSPPART"] = "403450706 ";
                    dwReturn["ZUART"] = "AKS-137             ";
                    dwReturn["ZUVAR"] = "1  ";
                    dwReturn["ZUFARBE"] = "RD001     ";
                    dwReturn["ZUDEZI"] = " ";
                    dwReturn["ZUME"] = "1";
                    dwReturn["ZUERLKZ"] = " ";
                    dwReturn["ZUIKOND"] = "0";
                    dwReturn["ZUFLAG"] = "S";
                    dwReturn["ZUNTAUSCH"] = " ";
                    dwReturn["ZUFILLER"] = "                          ";

                    #endregion
                    break;
                case "JLT":
                    #region====JLT======
                    dwReturn["ZUMANDANT"] = "00";
                    dwReturn["ZUAUFKRS"] = "ZT";
                    dwReturn["ZUAUFLFD"] = "000004";
                    dwReturn["ZUAUFPOS"] = "001";
                    dwReturn["ZUSA"] = "713";
                    dwReturn["ZUTEILNR"] = "0000";
                    dwReturn["ZUPOS"] = "01";
                    dwReturn["ZUPARTIE"] = "0000006";
                    dwReturn["ZUPARTIEKZ"] = "0";
                    dwReturn["ZULO"] = "01";
                    dwReturn["ZULB"] = "CS";
                    dwReturn["ZULBEHI"] = "0000000020";
                    dwReturn["ZUAENDZL"] = "0";
                    dwReturn["ZUAENDBEN"] = "        ";
                    dwReturn["ZUAENDDAT"] = "0";
                    dwReturn["ZUNEUBEN"] = "INTEXE  ";
                    dwReturn["ZUNEUDAT"] = "0";
                    dwReturn["ZUEINTKG"] = "32000";
                    dwReturn["ZUEINTSP"] = "0";
                    dwReturn["ZUEINTKA"] = "0";
                    dwReturn["ZUENTNKG"] = "0";
                    dwReturn["ZUENTNSP"] = "0";
                    dwReturn["ZUENTNKA"] = "0";
                    dwReturn["ZULIEFZWP"] = "          ";
                    dwReturn["ZUSPPART"] = "403450706 ";
                    dwReturn["ZUART"] = "AKS-137             ";
                    dwReturn["ZUVAR"] = "1  ";
                    dwReturn["ZUFARBE"] = "RD001     ";
                    dwReturn["ZUDEZI"] = " ";
                    dwReturn["ZUME"] = "1";
                    dwReturn["ZUERLKZ"] = " ";
                    dwReturn["ZUIKOND"] = "0";
                    dwReturn["ZUFLAG"] = "S";
                    dwReturn["ZUNTAUSCH"] = " ";
                    dwReturn["ZUFILLER"] = "                          ";

                    #endregion
                    break;
            }
            INTEXDBC.MapData(true, ref dwReturn, dwInput);
        }
        public DataRow Convert2ZUTEI(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryZUTEI(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region====YGR======
                    dwReturn["ZUMANDANT"] = "00";
                    dwReturn["ZUAUFKRS"] = "ZT";
                    dwReturn["ZUAUFLFD"] = "000004";
                    dwReturn["ZUAUFPOS"] = "001";
                    dwReturn["ZUSA"] = "713";
                    dwReturn["ZUTEILNR"] = "0000";
                    dwReturn["ZUPOS"] = "01";
                    dwReturn["ZUPARTIE"] = "0000006";
                    dwReturn["ZUPARTIEKZ"] = "0";
                    dwReturn["ZULO"] = "01";
                    dwReturn["ZULB"] = "CS";
                    dwReturn["ZULBEHI"] = "0000000020";
                    dwReturn["ZUAENDZL"] = "0";
                    dwReturn["ZUAENDBEN"] = "        ";
                    dwReturn["ZUAENDDAT"] = "0";
                    dwReturn["ZUNEUBEN"] = "INTEXE  ";
                    dwReturn["ZUNEUDAT"] = "0";
                    dwReturn["ZUEINTKG"] = "32000";
                    dwReturn["ZUEINTSP"] = "0";
                    dwReturn["ZUEINTKA"] = "0";
                    dwReturn["ZUENTNKG"] = "0";
                    dwReturn["ZUENTNSP"] = "0";
                    dwReturn["ZUENTNKA"] = "0";
                    dwReturn["ZULIEFZWP"] = "          ";
                    dwReturn["ZUSPPART"] = "403450706 ";
                    dwReturn["ZUART"] = "AKS-137             ";
                    dwReturn["ZUVAR"] = "1  ";
                    dwReturn["ZUFARBE"] = "RD001     ";
                    dwReturn["ZUDEZI"] = " ";
                    dwReturn["ZUME"] = "1";
                    dwReturn["ZUERLKZ"] = " ";
                    dwReturn["ZUIKOND"] = "0";
                    dwReturn["ZUFLAG"] = "S";
                    dwReturn["ZUNTAUSCH"] = " ";
                    dwReturn["ZUFILLER"] = "                          ";

                    #endregion
                    break;
                case "JLT":
                    #region====JLT======
                    dwReturn["ZUMANDANT"] = "00";
                    dwReturn["ZUAUFKRS"] = "ZT";
                    dwReturn["ZUAUFLFD"] = "000004";
                    dwReturn["ZUAUFPOS"] = "001";
                    dwReturn["ZUSA"] = "713";
                    dwReturn["ZUTEILNR"] = "0000";
                    dwReturn["ZUPOS"] = "01";
                    dwReturn["ZUPARTIE"] = "0000006";
                    dwReturn["ZUPARTIEKZ"] = "0";
                    dwReturn["ZULO"] = "01";
                    dwReturn["ZULB"] = "CS";
                    dwReturn["ZULBEHI"] = "0000000020";
                    dwReturn["ZUAENDZL"] = "0";
                    dwReturn["ZUAENDBEN"] = "        ";
                    dwReturn["ZUAENDDAT"] = "0";
                    dwReturn["ZUNEUBEN"] = "INTEXE  ";
                    dwReturn["ZUNEUDAT"] = "0";
                    dwReturn["ZUEINTKG"] = "32000";
                    dwReturn["ZUEINTSP"] = "0";
                    dwReturn["ZUEINTKA"] = "0";
                    dwReturn["ZUENTNKG"] = "0";
                    dwReturn["ZUENTNSP"] = "0";
                    dwReturn["ZUENTNKA"] = "0";
                    dwReturn["ZULIEFZWP"] = "          ";
                    dwReturn["ZUSPPART"] = "403450706 ";
                    dwReturn["ZUART"] = "AKS-137             ";
                    dwReturn["ZUVAR"] = "1  ";
                    dwReturn["ZUFARBE"] = "RD001     ";
                    dwReturn["ZUDEZI"] = " ";
                    dwReturn["ZUME"] = "1";
                    dwReturn["ZUERLKZ"] = " ";
                    dwReturn["ZUIKOND"] = "0";
                    dwReturn["ZUFLAG"] = "S";
                    dwReturn["ZUNTAUSCH"] = " ";
                    dwReturn["ZUFILLER"] = "                          ";

                    #endregion
                    break;
                default:
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwInput.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public DataSet QueryZUTEI(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM ZUTEI WHERE  ROWNUM<2 ";
                    SResult = Connect2Proxy(or1);

                    break;

                case 1:
                    or1.CommandText = "SELECT * FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD AND ZUAUFPOS=:ZUAUFPOS"; ;
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    or1.Parameters.Add("ZUAUFPOS", OracleType.NVarChar).Value = dwData["ZUAUFPOS"].ToString();
                    SResult = Connect2Proxy(or1);

                    break;
                case 3:
                    or1.CommandText = "SELECT * FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT AND  ZUSA= 610 AND  ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD"; ;
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    SResult = Connect2Proxy(or1);

                    break;
                case 4:
                    SResult = QZU04(dwData); break;
                case 5:
                    or1.CommandText = "SELECT DISTINCT ZUAUFKRS,ZUAUFLFD,ZUAUFPOS,ZUSA,ZUPOS,ZUART,ZUVAR,ZUFARBE,ZUSPPART,GPFBPART,GLLO,GLLB,GLLP,SUM(ZUEINTKG-ZUENTNKG) AS TOGET,"
                    + "SUM(ZUEINTKG) AS ZUEINTKG,SUM(ZUENTNKG) AS ZUENTNKG,MAX(LSNAME2) AS SELLER "
                    + " from zutei Z JOIN GLLG B  ON ZULBEHI=GLLBEHI "
                         + " LEFT JOIN GPDAT ON GPPARTIE=ZUPARTIE AND ZUPARTIEKZ=GPPARTIEKZ  "
                         + "  LEFT JOIN LIEFDAT ON GPLIEFNR=LSLIEFNR "
                         + " WHERE ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD AND ZUEINTKG-ZUENTNKG>0"
                         + " GROUP BY ZUAUFKRS,ZUAUFLFD,ZUAUFPOS,ZUSA,ZUPOS,ZUART,ZUVAR,ZUFARBE,ZUSPPART,GPFBPART,GLLO,GLLB,GLLP";
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    SResult = Connect2Proxy(or1);

                    break;
                case 6:
                    or1.CommandText = "SELECT DISTINCT T.*,GSHANDLNR,GSART,GSVAR,GSGARNBEZ,LPKBEZ,LPBEZ,ABAVKAUFKRS,ABAVKAUFLFD,ABAVKAUFPOS FROM ZUTEI  T JOIN ABAUFM ON ABAMANDANT=ZUMANDANT AND ABAAUFKRS=ZUAUFKRS AND ABAAUFLFD=ZUAUFLFD AND ABAAUFPOS=ZUAUFPOS"
                        + "  JOIN GPDAT ON ZUPARTIE=GPPARTIE AND ZUPARTIEKZ=GPPARTIEKZ JOIN GSDAT ON GSART=GPGART AND GSVAR=GPGVAR"
                        + " JOIN GLLG A ON GLLBEHI=ZULBEHI JOIN LAGPL ON A.GLLO=LPLO AND A.GLLB=LPLB AND A.GLLP=LPPLATZ"
                    + " WHERE ABAMANDANT=:ZUMANDANT AND ABAVKAUFKRS=:ZUAUFKRS AND ABAVKAUFLFD=:ZUAUFLFD"; ;
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    SResult = Connect2Proxy(or1);

                    break;
                case 7:
                    or1.CommandText = "SELECT VVLIEFSCH,P.* FROM ZUTEI P JOIN VVTLIEF ON VVTAUFKRS=ZUAUFKRS AND VVTAUFLFD=ZUAUFLFD AND VVTAUFPOS=ZUAUFPOS  JOIN VVLIEF ON VVLIEFSCH=VVTLIEFSCH  "
                               + " WHERE VVMANDANT=:VVMANDANT: AND  VVLIEFSCH=:VVLIEFSCH:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);

                    break;
                case 8:
                    or1.CommandText = "SELECT DISTINCT ZUAUFKRS,ZUAUFLFD,ZUAUFPOS,ZUSA,ZUPOS,LSNAME2 AS SELLER from zutei Z LEFT JOIN GPDAT ON GPPARTIE=ZUPARTIE LEFT JOIN LIEFDAT ON GPLIEFNR=LSLIEFNR   WHERE ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD ";
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = dwData["ZUMANDANT"].ToString();
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = dwData["ZUAUFKRS"].ToString();
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = dwData["ZUAUFLFD"].ToString();
                    SResult = Connect2Proxy(or1);

                    break;
                case 9:
                    SResult = QZU09(dwData);

                    break;
                case 10:
                    or1.CommandText = "SELECT M.*,GPGVAR FROM ZUTEI M "
                         + "  JOIN GPDAT ON ZUPARTIE=GPPARTIE AND ZUPARTIEKZ=GPPARTIEKZ  "
                        + " JOIN GLLG A ON GLLBEHI=ZULBEHI "
                    + " WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    SResult = Connect2Proxy(or1);
                    break;
                case 11: SResult = QZU11(dwData); break;
                case 12: SResult = QZU12(dwData); break;
            }
            SResult.Tables[0].TableName = "ZUTEI";

            return SResult;
        }
        public DataSet QZU04(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT M.*,GPGVAR,GSHANDLNR,GSART,GSVAR,GSGARNBEZ,LPKBEZ,LPBEZ FROM ZUTEI M "
                              + "  JOIN GPDAT ON ZUPARTIE=GPPARTIE AND ZUPARTIEKZ=GPPARTIEKZ JOIN GSDAT ON GSART=GPGART AND GSVAR=GPGVAR"
                              + " JOIN GLLG A ON GLLBEHI=ZULBEHI JOIN LAGPL ON A.GLLO=LPLO AND A.GLLB=LPLB AND A.GLLP=LPPLATZ"
                              + " WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QZU11(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ZUTEI "
                   + " WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS: AND  ZUSA=:ZUSA: AND ZUPOS=:ZUPOS:  AND ZULBEHI=:ZULBEHI:  ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QZU12(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT * FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND  ZULBEHI=:ZULBEHI:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QZU41(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT M.*,GPGVAR,GSHANDLNR,GSART,GSVAR,GSGARNBEZ,LPKBEZ,LPBEZ FROM ZUTEI M "
               + "  JOIN GPDAT ON ZUPARTIE=GPPARTIE AND ZUPARTIEKZ=GPPARTIEKZ JOIN GSDAT ON GSART=GPGART AND GSVAR=GPGVAR"
                  + " JOIN GLLG A ON GLLBEHI=ZULBEHI JOIN LAGPL ON A.GLLO=LPLO AND A.GLLB=LPLB AND A.GLLP=LPPLATZ"
              + " WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QZU09(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT B.*,PD.*,A.*,M.*,GPGVAR,GSHANDLNR,GSART,GSVAR,GSGARNBEZ,LPKBEZ,LPLBKZ,LPBEZ,GLLBEHI,0 as KG,99999999 AS FREEKG,0 AS ALLOKG FROM ZUTEI M "
             + "  JOIN GPDAT PD ON GPMANDANT=ZUMANDANT AND ZUPARTIE=GPPARTIE AND ZUPARTIEKZ=GPPARTIEKZ "
             + " JOIN GSDAT ON GSART=GPGART AND GSVAR=GPGVAR"
              + " JOIN GLLG A ON GLLBEHI=ZULBEHI "
              + " JOIN LAGPL ON A.GLLO=LPLO AND A.GLLB=LPLB AND A.GLLP=LPPLATZ"
              + " JOIN GPBST B ON  GPBMANDANT=GPMANDANT AND GPBLO=GLLO AND GPBLB=GLLB  AND GPBPARTIE=GPPARTIE AND GPBPARTIEKZ=GLPARTIEKZ  AND A.GLPARTIEKZ = GPPARTIEKZ "
              + " WHERE ZUMANDANT=:GAMANDANT: AND ZUAUFKRS=:GAAUFKRS: AND ZUAUFLFD=:GAAUFLFD: AND ZUAUFPOS=:GAAUFPOS: AND  ZUSA=:GASA: AND ZUPOS=:GAPOS:";

            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public DataSet QZU13(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT ZUMANDANT FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = TableName;
            return SResult;
        }
        public void DeleteZUTEI(DataRow dwData, int option = 1)
        {

            
            switch (option)
            {
                case 1:
                    DZU01(dwData);
                    break;
                case 2:
                    DZU02(dwData);
                    break;
            }
            
        }
        public void DZU01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "DELETE FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS: AND ZUSA=:ZUSA:  AND ZUPOS=:ZUPOS:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

            Connect2Proxy(or1);
        }
        public void DZU02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();

            or1.CommandText = "DELETE FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);

            Connect2Proxy(or1);
        }
        public void DZU03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand(); 
            or1.CommandText = "DELETE FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS: AND ZUSA=:ZUSA:  AND ZUPOS=:ZUPOS: AND ZULBEHI=:ZULBEHI:"; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
            Connect2Proxy(or1);
        }
        public void DeleteZUTEI(string client, string krs, string lfd, string pos, int option = 1)
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();

            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ZUTEI WHERE ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD AND ZUAUFPOS=:ZUAUFPOS";
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = lfd;
                    or1.Parameters.Add("ZUAUFPOS", OracleType.NVarChar).Value = pos;
                    break;
                case 2:
                    or1.CommandText = "DELETE FROM ZUTEI WHERE   ZUMANDANT=:ZUMANDANT AND ZUAUFKRS=:ZUAUFKRS AND ZUAUFLFD=:ZUAUFLFD ";
                    or1.Parameters.Add("ZUMANDANT", OracleType.NVarChar).Value = client;
                    or1.Parameters.Add("ZUAUFKRS", OracleType.NVarChar).Value = krs;
                    or1.Parameters.Add("ZUAUFLFD", OracleType.NVarChar).Value = lfd;

                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void MapZUTEI(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void InsertZUTEI(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                default:
                    or1.CommandText = "INSERT INTO ZUTEI(ZUMANDANT,ZUAUFKRS,ZUAUFLFD,ZUAUFPOS,ZUSA,ZUTEILNR,ZUPOS,ZUPARTIE,ZUPARTIEKZ,ZULO,ZULB,ZULBEHI,ZUAENDZL,ZUAENDBEN,ZUAENDDAT,ZUNEUBEN,ZUNEUDAT,ZUEINTKG,ZUEINTSP,ZUEINTKA,ZUENTNKG,ZUENTNSP,ZUENTNKA,ZULIEFZWP,ZUSPPART,ZUART,ZUVAR,ZUFARBE,ZUDEZI,ZUME,ZUERLKZ,ZUIKOND,ZUFLAG,ZUNTAUSCH,ZUFILLER)"
                    + " VALUES (:ZUMANDANT:,:ZUAUFKRS:,:ZUAUFLFD:,:ZUAUFPOS:,:ZUSA:,:ZUTEILNR:,:ZUPOS:,:ZUPARTIE:,:ZUPARTIEKZ:,:ZULO:,:ZULB:,:ZULBEHI:,:ZUAENDZL:,:ZUAENDBEN:,:ZUAENDDAT:,:ZUNEUBEN:,:ZUNEUDAT:,:ZUEINTKG:,:ZUEINTSP:,:ZUEINTKA:,:ZUENTNKG:,:ZUENTNSP:,:ZUENTNKA:,:ZULIEFZWP:,:ZUSPPART:,:ZUART:,:ZUVAR:,:ZUFARBE:,:ZUDEZI:,:ZUME:,:ZUERLKZ:,:ZUIKOND:,:ZUFLAG:,:ZUNTAUSCH:,:ZUFILLER:)";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
            }

            Connect2Proxy(or1);
        }
        public void UpdateZUTEI(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                default:
                    or1.CommandText = "UPDATE ZUTEI SET "
                        + "ZUTEILNR=:ZUTEILNR:,"
                        + "ZUPARTIE=:ZUPARTIE:,"
                        + "ZUPARTIEKZ=:ZUPARTIEKZ:,"
                        + "ZULO=:ZULO:,"
                        + "ZULB=:ZULB:,"
                        + "ZULBEHI=:ZULBEHI:,"
                        + "ZUAENDZL=:ZUAENDZL:,"
                        + "ZUAENDBEN=:ZUAENDBEN:,"
                        + "ZUAENDDAT=:ZUAENDDAT:,"
                        + "ZUNEUBEN=:ZUNEUBEN:,"
                        + "ZUNEUDAT=:ZUNEUDAT:,"
                        + "ZUEINTKG=:ZUEINTKG:,"
                        + "ZUEINTSP=:ZUEINTSP:,"
                        + "ZUEINTKA=:ZUEINTKA:,"
                        + "ZUENTNKG=:ZUENTNKG:,"
                        + "ZUENTNSP=:ZUENTNSP:,"
                        + "ZUENTNKA=:ZUENTNKA:,"
                        + "ZULIEFZWP=:ZULIEFZWP:,"
                        + "ZUSPPART=:ZUSPPART:,"
                        + "ZUART=:ZUART:,"
                        + "ZUVAR=:ZUVAR:,"
                        + "ZUFARBE=:ZUFARBE:,"
                        + "ZUDEZI=:ZUDEZI:,"
                        + "ZUME=:ZUME:,"
                        + "ZUERLKZ=:ZUERLKZ:,"
                        + "ZUIKOND=:ZUIKOND:,"
                        + "ZUFLAG=:ZUFLAG:,"
                        + "ZUNTAUSCH=:ZUNTAUSCH:,"
                        + "ZUFILLER=:ZUFILLER: "
                        + "   WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:  AND ZUSA=:ZUSA: AND ZUPOS=:ZUPOS: AND ZULBEHI=:ZULBEHI: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    Connect2Proxy(or1);
                    break;
                case 2:
                    UZU02(dwData);
                    break;
            }


        }
        public void UZU03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ZUTEI SET  ZUEINTKG=ZUEINTKG+:ZUEINTKG:  "
                      + "   WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:  AND ZUSA=:ZUSA: AND ZUPOS=:ZUPOS: AND ZULBEHI=:ZULBEHI: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void UZU02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ZUTEI SET  ZULO=:ZULO:, ZULB=:ZULB:, ZUEINTKG=:ZUEINTKG:, ZUFLAG=:ZUFLAG: "
                      + "   WHERE ZUMANDANT=:ZUMANDANT: AND ZUAUFKRS=:ZUAUFKRS: AND ZUAUFLFD=:ZUAUFLFD: AND ZUAUFPOS=:ZUAUFPOS:  AND ZUSA=:ZUSA: AND ZUPOS=:ZUPOS: AND ZULBEHI=:ZULBEHI: ";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void SaveZUTEI(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryZUTEI(dwData, 11);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapZUTEI(ref dwLocal, dwData);
            if (!flgExist)
            {
                InsertZUTEI(dwLocal, ITXDBVERSION);
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    UpdateZUTEI(dwLocal, 1);
                    break;
                case "JLT":
                    UpdateZUTEI(dwLocal, 1);
                    break;
            }
        }
    }
}
